// JavaScript Document
function showDiv(title){
	if(!document.getElementById('bellow_bg')){	
		createDiv(title);	
	}else{
		document.getElementById("ajaxtitle").innerHTML=title;
	}
	arrange_position();
}

function closeDiv(){
	document.getElementById('bellow_bg').style.display='none';
	document.getElementById('over_content').style.display='none';
}

function createDiv(title){
	var div=document.createElement('div');
	div.setAttribute('id','bellow_bg');
	div.setAttribute("class", 'bellow_bg');
	div.setAttribute("className", 'bellow_bg');
	var div1=document.createElement('div');
	div1.setAttribute('id','over_content');
	div1.setAttribute("class", 'over_content');
	div1.setAttribute("className", 'over_content');
	
	div1.innerHTML='<div class="top" id="top"><div class="title" id="ajaxtitle"> '+title+'</div><div class="close"><a href="javascript:;" onclick="closeDiv();">[关闭]</a></div></div><div class="ajaxcontent" id="ajaxcontent"></div>';
	
	document.body.insertBefore(div, document.body.firstChild);
	document.body.insertBefore(div1, document.body.firstChild);
	arrange_position();
}

function arrange_position(){
	var div=document.getElementById('bellow_bg');
	var div1=document.getElementById('over_content');
	var content=document.getElementById('ajaxcontent');
	div.style.height=document.body.scrollHeight;
	div1.style.top=document.body.scrollTop+150;
	content.innerHTML='';
	div.style.display='block';
	div1.style.display='block';
}

function getXMLHTTPObj()
 {
	  var C = null;
	  try{
		   C = new ActiveXObject("Msxml2.XMLHTTP");
	  }catch(e){
		   try{
				C = new ActiveXObject("Microsoft.XMLHTTP");
		   }catch(sc){
				C = null;
		   }
	  }
	  
	  if( !C && typeof XMLHttpRequest != "undefined" )
	  {
		   C = new XMLHttpRequest();
	  }
	  return C;
}

function updatePage(){
	  try {
		   var returnObj = document.getElementById(returnID);
		   if (xmlHttp.readyState == 1){
			returnObj.innerHTML = "<img src='http://www.fengsh8.com/img/loading.gif' /> 加载中，请稍候```";
		   }
		
		   if (xmlHttp.readyState == 2){
			returnObj.innerHTML = "<img src='http://www.fengsh8.com/img/loading.gif' /> 加载中，请稍候```";
		   }
		
		   if (xmlHttp.readyState == 3){
			returnObj.innerHTML = "<img src='http://www.fengsh8.com/img/loading.gif' /> 加载中，请稍候```";
		   }
		
		   if (xmlHttp.readyState == 4){
			   
			   var response = xmlHttp.responseText;
			   if(returnObj!=null){
				   if(returnObj.tagName=='INPUT'){
					   returnObj.value=response ;
				   }else{
					   returnObj.innerHTML=response ;
				   }
			   }
		   }
	  }catch(e){
		   var returnObj = document.getElementById(returnID);
		   if(returnObj!=null){
			   if(returnObj.tagName=='INPUT'){
				   returnObj.value="错误:" + e ; 
			   }else{
				   returnObj.innerHTML="错误:" + e ;
			   }
		   }
	  }
}
function getOs()   
{   
   var OsObject = "";   
   if(navigator.userAgent.indexOf("MSIE")>0) {   
        return "MSIE";       //IE浏览器
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){   
        return "Firefox";     //Firefox浏览器
   }
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {   
        return "Safari";      //Safan浏览器
   }
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){   
        return "Camino";   //Camino浏览器
   }
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){   
        return "Gecko";    //Gecko浏览器
   }   
} 

var xmlHttp=null;
var returnID=null;
function checkSelect(URL,title,returnid,makediv,cache){
	if(typeof(cache) == 'undefined'){
		cache=true;
	}
	var synchronization=false;
	if(makediv){
		showDiv(title);
		synchronization=false;
	}
	returnID=returnid;
		  try{
			   xmlHttp = getXMLHTTPObj();
			   if( xmlHttp ){
					var btype=getOs();
					xmlHttp.onreadystatechange = (btype!="Firefox")?(updatePage):(updatePage());
					xmlHttp.open("GET", URL, synchronization);
					if(!cache){
						xmlHttp.setRequestHeader("If-Modified-Since","0");
					}
					xmlHttp.send(null);
					//在firefox下，不会等到onreadystatechange执行完毕后才继续，所以下面还要补上一句再获取一次
					xmlHttp.onreadystatechange = (btype!="Firefox")?(updatePage):(updatePage());
			   }else{

					document.getElementById(returnid).innerHTML = "XMLHTTP对象创建失败";
			   }
		  }catch (e){
			   document.getElementById(returnid).innerHTML = "错误:" + e;
		  }
}

function getElementByClassName(name,obj){
	checkNode(obj,name.toLowerCase(),arr=new Array());
	return arr;
}

function checkNode(node,cname,arr){
	if(node.hasChildNodes()){
		var obj=node.childNodes;
		for(var i=0;i<obj.length;checkNode(obj[i],cname,arr),i++);
	}

	try{
		if(node.className!=null){
			var cnames=node.className.split(' '); 
			for(var i=0;i<cnames.length;(cnames[i].toLowerCase()==cname)?arr.push(node):null,i++);
		}
	}catch(err){}
}


